<template>
  <el-radio-group v-model="mValue" @input="handleChange">
    <el-radio v-for="(item,index) in codeData"
      :label="item.value"
      :key="index">
      {{item.text}}
    </el-radio>
  </el-radio-group>
</template>
<script>
import {codeProvider} from '@/assets/js/quick/provider.js'
export default {
  name: 'bms-radio',
  props:{
    value : {type: null ,default:''},
    codeType : {type:String,default:''},
    condition : {type:Object,default:()=>{}}
  },
  data(){
    return {
      mValue: this.value,
      codeData : []
    }
  },
  watch : {
    value: {
      handler(newValue,oldValue) {
        this.initData();
      },
      deep: true
    },
    codeType: {
      handler(newValue,oldValue) {
        this.initData();
      },
      deep: true
    },
    condition: {
      handler(newValue,oldValue) {
        this.initData();
      },
      deep: true
    },
  },
  methods : {
    handleChange(val) {
      this.$emit('input',val);
      this.$emit('change',val);
    },
    async initData() {
      if(this.codeType) {
        let _this = this
        await codeProvider.getList(this.codeType,this.condition || {}).then(resp => {
          _this.codeData = resp
        }).catch(err => {
          _g.toastMsg("error",err)
        })
      } else {
        console.error('codeType is not empty!');
      }
    }
  },
  created(){
    this.initData();
  },
  mounted(){
  }
}
</script>
<style scoped lang="scss">

</style>

